import Vue from 'vue'
import Previewer from './index.vue'

const PreviewerConstructor = Vue.extend(Previewer)
let instance = null
let getAnInstance = () => {
  if (!instance) {
    instance = new PreviewerConstructor({
      el: document.createElement('div')
    })
  }
  return instance
}

let imgPreview = ({imgList = [], options = {}, index = 0, closed = function () {}}) => {
  let instance = getAnInstance()
  instance.list = imgList
  instance.options = options
  instance.closed = closed
  document.body.appendChild(instance.$el)
  instance.show(index)
  return instance
}
function closePreview() {
  let instance = getAnInstance()
  instance.close()
}
export {imgPreview, closePreview}
